<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>扫一扫</title>
    <!-- 引入 WeUI -->
    <link rel="stylesheet" href="http://jxt.anan365.com/jiaofei/Public/weui-1.1.2/dist/style/weui.css"/>
    <script src="http://jxt.anan365.com/jiaofei/Public/jquery.js"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
</head>
<body ontouchstart>

</body>
</html>
<script>
    $(function () {
        wx.config({
            debug: false,
            appId: 'wxe17c19bfa5f3f56e',
            timestamp: <?php echo $time;?>,
            nonceStr: '<?php echo $str;?>',
            signature: '<?php echo $sign;?>',
            jsApiList: ['scanQRCode'] // 必填，需要使用的JS接口列表
        });

        //验证成功
        wx.ready(function(){
            wx.scanQRCode({
                needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果
                scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
                success: function (res) {
                    var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
                    var arr = result.split("&");
                    for(var i in arr){
                        if(i == 0 && arr[i] !== "code=anan"){
                            alert("二维码不正确");
                            return false;
                        }
                        if(i == 1 ){
                            var school = arr[i].split("=");
                            if(school[0] != "fid" || !school[1]){
                                alert("学校id参数不正确");
                                return false;
                            }
                        }
                        if(i == 2){
                            var school = arr[i].split("=");
                            if(school[0] != "fname" || !school[1]){
                                alert("学校名称参数不正确");
                                return false;
                            }
                        }

                    }
                    location.href = "http://jxt.anan365.com/jiaofei/index.php/Home/Index/school_setpay/key/"+result;
                }
            });
        });

        //验证失败
        wx.error(function(res){
            alert(res.errMsg);
        });
    })
</script>
